﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Wage
{
    public class SalaryItem
    {
        [MaxLength(50)]
        [Required]
        public string Name { get; set; }
        [Required]
        public decimal Amount { get; set; }
        [Required]
        public DateTime Time { get; set; }

        public int SalaryItemId { get; set; }
        public bool Validation { get; set; } = true;

    }
    public class SalaryShow
    {
        public SalaryShow(SalaryItem salary)
        {
            Name = salary.Name;
            Amount = salary.Amount;
        }
        private string Name { get; set; }
        private decimal Amount { get; set; }
        public override string ToString()
        {
            return Name.PadRightWhileDouble(20, ' ') + ": " + Amount.ToString();
        }
    }

    public class SalaryMonth
    {

        public List<SalaryItem> TotalItems { get; set; }

        public DateTime Time { get; set; }

        public decimal Total { get; set; }
        public SalaryMonth()
        {
            TotalItems = new List<SalaryItem>();
        }

    }
    public class SalaryNameComparer : IEqualityComparer<SalaryItem>
    {
        public bool Equals(SalaryItem x, SalaryItem y)
        {
            if (x == null)
                return y == null;
            return x.Name == y.Name;
        }

        public int GetHashCode(SalaryItem obj)
        {
            if (obj == null)
                return 0;
            return obj.Name.GetHashCode();
        }
    }
    public class SalaryTimeComparer : IEqualityComparer<SalaryItem>
    {
        public bool Equals(SalaryItem x, SalaryItem y)
        {
            if (x == null)
                return y == null;
            return x.Time - y.Time == TimeSpan.Zero;
        }

        public int GetHashCode(SalaryItem obj)
        {
            if (obj == null)
                return 0;
            return obj.Time.GetHashCode();
        }
    }

    public class WageCalculatioResult
    {
        /// <summary>
        /// 包含所有表头的总数
        /// </summary>
        public List<SalaryItem> TotalItems { get; set; }
        //按月的总数
        public List<SalaryMonth> SalaryByMonth { get; set; }
        //总计
        public decimal Total { get; set; }

    }
}
